<template>
  <div class="ams-s">
    <div class="ams-sel-method rx_no_select">
      <div class="btn btn-sel">{{ selMethod }}</div>
      <div class="guide">---></div>
    </div>
    <div class="ams-list rx_no_select">
      <div
        v-for="(item,index) in methodList"
        :key="'m-list-' + index"
        class="btn list-btn"
        :class="{ 'select': selMethod === item }"
        @click="onclick(index)"
      >
        <span>{{ item }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    method: { type: String, value: 'GET' },
  },
  data() {
    return {
      selMethod: 'GET',
      methodList: ['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS', 'PATCH'],
    };
  },
  created() {
    this.configMethod()
  },
  methods: {
    configMethod() {
      let method = this.method || 'GET'
      const list = this.methodList;
      if (list.indexOf(method) === -1) {
        method = 'GET'
      }
      this.selMethod = method;
    },
    onclick(index) {
      const list = this.methodList;
      if (index > list.length) return;
      this.selMethod = list[index];
    },
  },
};
</script>

<style src="../css-component/style.css"></style>
<style scoped>
.ams-s {
  padding: 10px 30px;
  position: relative;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  font-size: 12px;
  align-items: center;
  color: white;
  cursor: pointer;
}

.ams-s .btn {
  height: 24px;
  padding: 0 20px;
  line-height: 24px;
  border-radius: 12px;
}

.ams-s .ams-sel-method {
  display: flex;
  flex-direction: row;
  align-items: center;
  cursor: pointer;
}

.ams-s .ams-sel-method .btn-sel {
  background-color: var(--color-orange);
}

.ams-s .ams-sel-method .guide {
  margin-left: 10px;
  color: var(--color-gray);
}

.ams-s .ams-list {
  margin-left: 10px;
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  padding: 0 10px 10px 10px;
  background-color: #eee;
  border-radius: 4px;
  box-shadow: 0px 1px 6px 0px rgba(245, 245, 23, 0.4);
}

.ams-s .ams-list .list-btn {
  margin-top: 10px;
  margin-left: 10px;
  background-color: var(--color-gray);
}

.ams-s .ams-list .list-btn.select {
  background-color: var(--color-orange);
}
</style>